package com.primi.chen.security;

import com.primi.chen.security.rsa.EkycVerification;
import com.primi.chen.security.rsa.RsaCreateFactorys;
import org.w3c.dom.Document;

import java.io.File;
import java.nio.file.Files;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;

/**
 * @author Primi.Chen(Chenxiangxu)
 * @apiNote 安全校验
 * <p>
 * Create AT 2020/3/6 10:19:10:19
 */
public class SecurityMain {
    EkycVerification verification;

    public SecurityMain() throws Exception {
        verification = new EkycVerification();
    }

    public static void main(String[] args) throws Exception {
        SecurityMain security = new SecurityMain();

        security.testRsa();


    }

    private void testRsa() throws Exception {
        // 带盐 测试;
        String slatKey = "test@ddd";
        String sourceString = "test_source";
        PublicKey publicKey = RsaCreateFactorys.getPublicKey(RsaCreateFactorys.KEY_SIZE, slatKey);
        String encodeString = RsaCreateFactorys.rsaEncode(sourceString, publicKey);
        System.out.println("[SLAT] Source : " + sourceString);
        System.out.println("[SLAT] ENCIODE : " + encodeString);
        PrivateKey privateKey = RsaCreateFactorys.getPrivateKey(RsaCreateFactorys.KEY_SIZE, slatKey);
        String dataDecoded = RsaCreateFactorys.rsaDecode(encodeString, privateKey);
        System.out.println("[SLAT] Decode:" + dataDecoded);
        //new File()
        String xml = "/Users/fomky/Desktop/open/bigdata-learnning/security/src/main/resources/uidai.xml";
        byte[] data = Files.readAllBytes(new File(xml).toPath());
        String contentData = new String(data);
        boolean checkSstatus = verification.checkXMLData(contentData);
        System.out.println("CheckResult: " + checkSstatus);
    }

}
